<template>
	<view>
		<Sheader :title="'服务者登录'"/>
		<view class="content">
			<u-image width="180rpx" class="logo" height="220rpx" :src="src"></u-image>
			<view class="form">
				<u-form :model="form" ref="uForm">
					<u-form-item label-width="170" label="服务者账号">
						<u-input v-model="form.loginName" placeholder="请输入身份证号码" />
					</u-form-item>
					<u-form-item label-width="170" label="登录密码">
						<u-input v-model="form.passWord" type="password" placeholder="请输入登录密码" maxlength="16" :password-icon="false"/>
					</u-form-item>
				</u-form>
			</view>
			<view class="login-btn" @click="loginFn">
				<text>登录</text>
			</view>
			<view class="btns-line">
				<view @click="$utils.gotoPage(`./register`)">服务者注册</view>
				<text @click="$utils.gotoPage(`./retrievePassword`)">找回密码</text>
			</view>
		</view>
	</view>
</template>

<script>
	import Sheader from '@/components/Sheader/index.vue'
	import logo from '@/static/login-logo.png'
	export default {
		data() {
			return {
				src: logo,
				form: {
					loginName: '',
					passWord: ''
				}
			}
		},
		components: {
			Sheader
		},
		async onLoad() {
			this.$http.setToken('', 1)
			this.$http.setUserType('')
		},
		onUnload() {
		},
		methods: {
			async loginFn() {
				if(!this.$u.test.idCard(this.form.loginName)) {
					uni.showToast({
						title: '请输入正确的身份证号',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if (!this.form.passWord) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none',
						duration: 2000
					})
					return
				}
				const res = await this.$http.request('/provider/login', this.form, 'post', true)
				if (res.success) {
					this.$http.setToken(res.data.data.token, 2)
					this.$http.setUserType('2')
					uni.setStorageSync("fw_viterInfo", res.data.data || {})
					uni.showToast({
						title: res.msg,
						icon: 'success',
						duration: 2000
					})
					let timer = setTimeout(() => {
						clearTimeout(timer)
						timer = null
						uni.reLaunch({
							url: '/pages/user/index'
						});
					}, 1000)
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		background: #2979FF;
		padding-top: 90rpx;
		height: 100vh;
	}

	.logo {
		margin-top: 160rpx;
	}
	.login-btn {
		width: 88vw;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #FFFFFF;
		opacity: 1;
		border-radius: 8rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #2979FF;
		opacity: 1;		
		margin: 40rpx 0 30rpx;
	}
	.btns-line {
		width: 88vw;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;		
	}
	.form {
		width: 88vw;
		margin-top: 52rpx;
	}
	.form /deep/ .u-form-item__body {
		font-weight: 500;	
		font-family: PingFang SC;
		color: #fff;
	}
	.form /deep/ .u-input__input {
		font-weight: 500;	
		font-family: PingFang SC;
		color: #fff;
	}
	.form /deep/ .u-border-bottom {
		/* border-bottom: 1px solid #F6F6F9 !important;		 */
	}
	.form /deep/ .uni-input-placeholder {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ECF5FF !important;
	}
</style>
